<template>
	<view class="page">
	
		<view class="content-block" v-if="detail">
			<view class="info-item">
				<view class="label">车牌号码</view>
				<view class="value">{{detail.plateNumber}}</view>
			</view>
			<view class="info-item">
				<view class="label">违章日期</view>
				<view class="value">{{formatDate(detail.violationDate)}}</view>
			</view>
			<view class="info-item">
				<view class="label">上传时间</view>
				<view class="value">{{detail.createdAt}}</view>
			</view>
			<view class="image-block">
				<view class="label">违章信息</view>
				<image v-if="detail.pic" :src="getImageUrl(detail.pic)" class="violation-image" mode="aspectFit" @click="previewImage"></image>
				<view v-else class="no-image">暂无图片</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { getViolationDetailApi } from '@/api/violation.js'

	export default {
		data() {
			return {
				detail: null,
				cloudStorage: 'https://suzhou-taxi-1306862033.cos.ap-chengdu.myqcloud.com/file/'
			}
		},
		methods: {
			getDetail(id) {
				getViolationDetailApi({id}).then(res => {
					this.detail = res
				
				})
			},
			getImageUrl(pic) {
				if(!pic) return ''
				return this.cloudStorage + pic
			},
			previewImage() {
				if(!this.detail.pic) return
				uni.previewImage({
					urls: [this.getImageUrl(this.detail.pic)],
					current: this.getImageUrl(this.detail.pic)
				})
			},
			formatDate(dateStr) {
				if(!dateStr) return ''
				const date = new Date(dateStr)
				const year = date.getFullYear()
				const month = date.getMonth() + 1
				const day = date.getDate()
				return `${year}年${month}月${day}日`
			}
		},
		onLoad(options) {
			if(options.id) {
				this.getDetail(options.id)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		background-color: #F7F6F9;
		min-height: 100vh;
		.content-block {
			padding: 30rpx;
			.info-item {
				background-color: #fff;
				padding: 30rpx;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);
				.label {
					font-size: 28rpx;
					color: #666;
				}
				.value {
					font-size: 32rpx;
					color: #333;
					font-weight: bold;
				}
			}
			.image-block {
				background-color: #fff;
				padding: 30rpx;
				border-radius: 20rpx;
				box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);
				.label {
					font-size: 28rpx;
					color: #666;
					margin-bottom: 20rpx;
				}
				.violation-image {
					width: 100%;
					height: 400rpx;
					border-radius: 10rpx;
				}
				.no-image {
					height: 400rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					color: #999;
					font-size: 28rpx;
				}
			}
		}
	}
</style> 